package com.g8.pethospitallearnbackend.mapper;

import com.g8.pethospitallearnbackend.entity.Learnprocess;
import com.g8.pethospitallearnbackend.entity.LearnprocessExample;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface LearnprocessMapper {
    @SelectProvider(type=LearnprocessSqlProvider.class, method="countByExample")
    long countByExample(LearnprocessExample example);

    @DeleteProvider(type=LearnprocessSqlProvider.class, method="deleteByExample")
    int deleteByExample(LearnprocessExample example);

    @Delete({
        "delete from learnprocess",
        "where pro_id = #{proId,jdbcType=VARCHAR}"
    })
    int deleteByPrimaryKey(String proId);

    @Insert({
        "insert into learnprocess (pro_id, pro_name, ",
        "`order`, is_visible, ",
        "modules)",
        "values (#{proId,jdbcType=VARCHAR}, #{proName,jdbcType=VARCHAR}, ",
        "#{order,jdbcType=INTEGER}, #{isVisible,jdbcType=TINYINT}, ",
        "#{modules,jdbcType=VARCHAR})"
    })
    int insert(Learnprocess record);

    @InsertProvider(type=LearnprocessSqlProvider.class, method="insertSelective")
    int insertSelective(Learnprocess record);

    @SelectProvider(type=LearnprocessSqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="pro_id", property="proId", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="pro_name", property="proName", jdbcType=JdbcType.VARCHAR),
        @Result(column="order", property="order", jdbcType=JdbcType.INTEGER),
        @Result(column="is_visible", property="isVisible", jdbcType=JdbcType.TINYINT),
        @Result(column="modules", property="modules", jdbcType=JdbcType.VARCHAR)
    })
    List<Learnprocess> selectByExample(LearnprocessExample example);

    @Select({
        "select",
        "pro_id, pro_name, `order`, is_visible, modules",
        "from learnprocess",
        "where pro_id = #{proId,jdbcType=VARCHAR}"
    })
    @Results({
        @Result(column="pro_id", property="proId", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="pro_name", property="proName", jdbcType=JdbcType.VARCHAR),
        @Result(column="order", property="order", jdbcType=JdbcType.INTEGER),
        @Result(column="is_visible", property="isVisible", jdbcType=JdbcType.TINYINT),
        @Result(column="modules", property="modules", jdbcType=JdbcType.VARCHAR)
    })
    Learnprocess selectByPrimaryKey(String proId);

    @UpdateProvider(type=LearnprocessSqlProvider.class, method="updateByExampleSelective")
    int updateByExampleSelective(@Param("record") Learnprocess record, @Param("example") LearnprocessExample example);

    @UpdateProvider(type=LearnprocessSqlProvider.class, method="updateByExample")
    int updateByExample(@Param("record") Learnprocess record, @Param("example") LearnprocessExample example);

    @UpdateProvider(type=LearnprocessSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Learnprocess record);

    @Update({
        "update learnprocess",
        "set pro_name = #{proName,jdbcType=VARCHAR},",
          "`order` = #{order,jdbcType=INTEGER},",
          "is_visible = #{isVisible,jdbcType=TINYINT},",
          "modules = #{modules,jdbcType=VARCHAR}",
        "where pro_id = #{proId,jdbcType=VARCHAR}"
    })
    int updateByPrimaryKey(Learnprocess record);

    @Select("SELECT * from learnprocess")
    List<Learnprocess> selectAllProcesses();

    @Select("SELECT MAX(l.order) FROM learnprocess l; ")
    int selectMaxOrder();

    @Select("select `order` from learnprocess where pro_id=#{proId}")
    Integer selectOrderById(@Param("proId") String proId);

    @Select("select * from learnprocess where `order`>=#{deletedOrder}")
    List<Learnprocess> selectLargerThanOrder(@Param("deletedOrder") Integer deletedOrder);

    @Select("select * from learnprocess where `order`>=#{left} and `order`<#{right}")
    List<Learnprocess> selectBetweenOrder(@Param("left") Integer left, @Param("right") Integer right);

    @Select("select * from learnprocess order by `order`;")
    List<Learnprocess> selectAllProcessesByOrder();

    @Select("select pro_name from learnprocess")
    List<String> selectAllProNames();

    @Select("select * from learnprocess where pro_id=#{proId}")
    Learnprocess selectProcessById(@Param("proId") String proId);

    @Select("select modules from learnprocess;")
    List<String> selectAllModulesUsed();
}